"""
房屋服务类
"""
from house import *
class HouseService:
    #定义属性houses列表,存放房屋信息
    houses = []
    # 定义属性id_counter:记录当前房屋的id
    id_counter = 1

    #使用构造方法  完成数据的初始化
    def __init__(self):
        #为了测试方便，我们在houses列表中增加一个测试数据
        house = House(1 , "tim" , "118" , "海淀" , 800 , "未出租")
        self.houses.append(house)

    def find_by_id(self , find_id):
        """
        根据find_id返回对应的House对象,不存在返回None
        """
        #遍历Houses
        for house in self.houses:
            if find_id == house.id:
                return house

    def del_by_id(self , del_id):
        """
        根据接收到的id删除房屋
        :param del_id
        :return
        """
        house = self.find_by_id(del_id)
        #如果查找的房源信息不存在
        if house is None:
            return False
        #如果找到了该house,就删除
        self.houses.remove(house)
        return True




    def get_houses(self):
        """
        返回房屋的列表信息
        """
        return self.houses



    #添加房屋信息
    def add(self , new_house:House):
        """
            将接收到的new_house添加到houses
            :param new_house
            :return
        """
        #分配id给new_house
        self.id_counter += 1
        new_house.id = self.id_counter
        self.houses.append(new_house)
